package org.ysu.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.ysu.entity.Role;
import org.ysu.service.RoleService;
import org.ysu.vo.ResultVO;

import javax.annotation.Resource;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author CaoYuJia
 * @since 2024-08-14
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Resource
    RoleService roleService;
    @GetMapping("/list")
    ResultVO<IPage<Role>> list(Integer pageNo,Integer pageSize){
        return ResultVO.success(roleService.list(pageNo,pageSize));
    }
    @PostMapping("/add")
    ResultVO<Boolean>add(String name,String description){
        return ResultVO.success(roleService.add(name,description));
    }
    @PostMapping("/update")
    ResultVO<Boolean>update(Long id,String name,String description){
        return ResultVO.success(roleService.update(id,name,description));
    }
    @PostMapping("/del")
    ResultVO<Boolean>del(Long id,Boolean status){
        return ResultVO.success(roleService.del(id,status),status?"启用角色成功":"禁用角色成功");
    }
    @GetMapping("/getById")
    ResultVO<Role>getById(Long id){
        return ResultVO.success(roleService.getById(id));
    }
    @GetMapping("/check")
    ResultVO<Boolean>check(Long id,String field,String value){
        return ResultVO.success(roleService.check(id,field,value));
    }
}
